]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
polkitAgent: Use a timeout for resetting the dialog
authorJonas Dreßler <verdre@v0yd.nl>
Sun, 23 Jun 2019 14:32:29 +0000 (16:32 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 5 Nov 2019 17:52:33 +0000 (18:52 +0100)
Since polkit takes a few milliseconds from initiating the session to
emitting the "request" signal, don't introduce visual distraction by
hiding the password entry and showing it again a few ms later.

So start a timeout of 200 ms when we destroy a session and if no session
request (i.e. a request for a password-authentication) happened during
this timeout, hide the password entry.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/788

js/ui/components/polkitAgent.js

index 6367bcc8f10839ee01b2839d6fedee1399878902..1a11c0b7eb5108c3c0c91d14134a997dd4ab6a64 100644 (file)
@@ -15,6 +15,8 @@ var DIALOG_ICON_SIZE = 48;
 
 var WORK_SPINNER_ICON_SIZE = 16;
 
+const DELAYED_RESET_TIMEOUT = 200;
+
 var AuthenticationDialog = GObject.registerClass({
     Signals: { 'done': { param_types: [GObject.TYPE_BOOLEAN] } }
 }, class AuthenticationDialog extends ModalDialog.ModalDialog {
@@ -160,7 +162,8 @@ var AuthenticationDialog = GObject.registerClass({
     }
 
     performAuthentication() {
-        this._destroySession();
+        this._destroySession(DELAYED_RESET_TIMEOUT);
+
         this._session = new PolkitAgent.Session({ identity: this._identityToAuth,
                                                   cookie: this._cookie });
         this._sessionCompletedId = this._session.connect('completed', this._onSessionCompleted.bind(this));
@@ -253,6 +256,11 @@ var AuthenticationDialog = GObject.registerClass({
     }
 
     _onSessionRequest(session, request, echoOn) {
+        if (this._sessionRequestTimeoutId) {
+            GLib.source_remove(this._sessionRequestTimeoutId);
+            this._sessionRequestTimeoutId = 0;
+        }
+
         // Cheap localization trick
         if (request == 'Password:' || request == 'Password: ')
             this._passwordLabel.set_text(_("Password:"));
@@ -292,7 +300,7 @@ var AuthenticationDialog = GObject.registerClass({
         this._ensureOpen();
     }
 
-    _destroySession() {
+    _destroySession(delay = 0) {
         if (this._session) {
             if (!this._completed)
                 this._session.cancel();
@@ -305,9 +313,23 @@ var AuthenticationDialog = GObject.registerClass({
             this._session = null;
         }
 
-        this._passwordBox.hide();
-        this._cancelButton.grab_key_focus();
-        this._okButton.reactive = false;
+        if (this._sessionRequestTimeoutId) {
+            GLib.source_remove(this._sessionRequestTimeoutId);
+            this._sessionRequestTimeoutId = 0;
+        }
+
+        let resetDialog = () => {
+            this._passwordBox.hide();
+            this._cancelButton.grab_key_focus();
+            this._okButton.reactive = false;
+        };
+
+        if (delay) {
+            this._sessionRequestTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, delay, resetDialog);
+            GLib.Source.set_name_by_id(this._sessionRequestTimeoutId, '[gnome-shell] this._sessionRequestTimeoutId');
+        } else {
+            resetDialog();
+        }
     }
 
     _onUserChanged() {
@@ -332,7 +354,10 @@ var AuthenticationDialog = GObject.registerClass({
     _onDialogClosed() {
         if (this._sessionUpdatedId)
             Main.sessionMode.disconnect(this._sessionUpdatedId);
-        this._sessionUpdatedId = 0;
+
+        if (this._sessionRequestTimeoutId)
+            GLib.source_remove(this._sessionRequestTimeoutId);
+        this._sessionRequestTimeoutId = 0;
 
         if (this._user) {
             this._user.disconnect(this._userLoadedId);